package com.xb.service.imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xb.entity.Stock;
import com.xb.mapper.StockMapper;
import com.xb.service.IStockService;
import com.xb.util.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * entityService业务层处理
 */
@Service
public class StockServiceImp implements IStockService {
    @Resource
    private StockMapper stockMapper;

    /**
     * 分页查询entity列表
     *
     * @param stock entity
     * @return entity
     */
    @Override
    public Result selectStockList(Stock stock, Integer page, Integer limit) {
        Result result = new Result();
        PageHelper.startPage(page, limit);
        List<Stock> list = stockMapper.selectStockList(stock);
        PageInfo<Stock> stockPageInfo = new PageInfo<>(list);
        if (stockPageInfo.getList() != null) {
            result.setMessage("查询成功！");
            result.setStatus(Result.RESPONSE_SUCCESS);
            result.setData(stockPageInfo.getList());
            result.setTotal(stockPageInfo.getTotal());
        }
        return result;
    }


    /**
     * 删除entity信息
     *
     * @param id entityID
     * @return 结果
     */
    @Override
    public int deleteStockById(Integer id) {
        return stockMapper.deleteStockById(id);
    }
}
